package com.servlet.request; /**
 * @author wzm
 * @create 2023-11-06 11:26
 * project_name:web2310
 * @Description
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;

@WebServlet("/req6")
public class RequestServlet6 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doPost(request, response);//调用doPost
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //乱码
        //设置字符输入流的编码，设置字符集和原本的html页面一致
        request.setCharacterEncoding("UTF-8");
        String username = request.getParameter("username");
        System.out.println("username = " + username);


//        BufferedReader reader = request.getReader();
//        String s = reader.readLine();
//        System.out.println("s = " + s);
        
        String name = "好好学习";
        //方案一
        //name = new String(name.getBytes("ISO-8859-1"), "UTF-8");

        //方式二
        String encode = URLEncoder.encode(name, "UTF-8");//%e5%bcc4%
        String decode = URLDecoder.decode(name, "ISO-8859-1");//好好学习
//        String decode = URLDecoder.decode(encode, "ISO-8859-1");//a/1

    }
}
